﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EveruComponent
{
    /// <summary>
    /// Returnes Random Number, based on the System.Security.Cryptography.RandomNumberGenerator.
    /// </summary>
    public class Random
    {
        System.Security.Cryptography.RandomNumberGenerator p_Generator = System.Security.Cryptography.RandomNumberGenerator.Create();

        #region Int32
        /// <summary>
        /// Get a new Int32 Number
        /// </summary>
        /// <returns></returns>
        public Int32 NextInt32()
        {
            byte[] RBits = new byte[4];
            p_Generator.GetBytes(RBits);
            int RNum = BitConverter.ToInt32(RBits, 0);

            return RNum;
        }
        #endregion

        #region Int64
        /// <summary>
        /// Get a new Int64 Number
        /// </summary>
        /// <returns></returns>
        public Int64 NextInt64()
        {
            byte[] RBits = new byte[8];
            p_Generator.GetBytes(RBits);
            Int64 RNum = BitConverter.ToInt64(RBits, 0);

            return RNum;
        }
        #endregion

        #region double

        /// <summary>
        /// Get a new Int32 Number
        /// </summary>
        /// <returns></returns>
        public double NextDouble()
        {
            byte[] RBits = new byte[8];
            p_Generator.GetBytes(RBits);
            long RNum = BitConverter.ToInt64(RBits, 0);

            if (RNum < 0)
            {
                return (double)RNum / (double)long.MinValue;
            }
            else
            {
                return (double)RNum / (double)long.MaxValue;
            }
        }

        #endregion

    }
}
